package com.Controller;

import com.Service.SubjectService;
import com.Utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/Subject")
public class SubjectController {
    @Autowired
    private SubjectService subjectService=new SubjectService();
    @GetMapping("/HomeFind")
    public R HomeFind(){
        if(subjectService.HomeFind()!=null){
            return new R(true,subjectService.HomeFind());
        }
        return new R(false);
    }
    @GetMapping("/ListFind")
    public R ListFind(){
        if(subjectService.ListFind()!=null){
            return new R(true,subjectService.ListFind());
        }
        return new R(false);
    }
    @PostMapping("/addSubject")
    public R addSubject(@RequestBody Map<String,String> Map_All){
        String subject1=Map_All.get("subject1");
        String subject2=Map_All.get("subject2");
        String subject3=Map_All.get("subject3");
        return new R(subjectService.addSubject(subject1,subject2,subject3)>0);
    }
    @PostMapping("/updataSubject")
    public R updataSubject(@RequestBody Map<String,String> Map_All){
        int id= Integer.parseInt(Map_All.get("id"));
        String subject1=Map_All.get("subject1");
        String subject2=Map_All.get("subject2");
        String subject3=Map_All.get("subject3");
        return new R(subjectService.updataSubject(id,subject1,subject2,subject3)>0);
    }
    @PostMapping("/delSubject")
    public R delSubject(@RequestBody Map<String,String> Map_All){
        int id= Integer.parseInt(Map_All.get("id"));
        return new R(subjectService.delSubject(id)>0);
    }

}
